﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using BLL;

namespace QLKhachsan
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            dtl_room.DataSource = (new B_Phong()).GetAll();
            dtl_room.DataBind();
            for (int i = 0; i < dtl_room.Items.Count; i++)
            {
                HiddenField hdfStatus = (HiddenField)dtl_room.Items[i].FindControl("hdf_status");
                LinkButton lbtReserv = (LinkButton)dtl_room.Items[i].FindControl("lbt_reserv");
                LinkButton lbtDetails = (LinkButton)dtl_room.Items[i].FindControl("lbl_details");

                // 1: Phòng trống, click vào chuyển sang trang đặt phòng
                if (hdfStatus.Value == "1")
                {
                    dtl_room.Items[i].CssClass = "empty";

                    lbtReserv.Visible = true;
                    lbtDetails.Visible = false;
                }
                //2: Phòng đã có khách, chuyển sang trang chi tiết
                else if (hdfStatus.Value == "2")
                {
                    dtl_room.Items[i].CssClass = "using";
                    lbtReserv.Visible = false;
                    lbtDetails.Visible = true;
                }
            }
        }

        protected void dtl_room_ItemCommand(object source, DataListCommandEventArgs e)
        {
            if (e.CommandName == "Reserv")
            {
                Response.Redirect("~/DatPhong.aspx");
            }
            else if (e.CommandName == "Details")
            {
                Response.Redirect("~/ChiTietPhong.aspx");
            }
        }
    }
}